<template>
	<view>
		
	</view>
</template>
<script>
	/**
	 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
	 */
	import base64 from '@/common/base64.js';
	import {validatenull} from '@/common/validate.js'
	import md5 from '@/common/md5.min.js'

	export default {
		data() {
			return {
				phoneNo: '',
				username: '',
				password: '',
				loginType: 'currentPhone',
				showPassword: false,
				remember: true,
				isValidCodeLogin: false,
				validCode: '',
				imgValidCodeSrc: null,
				list: [{
					name: '用户名'
				}, {
					name: '手机号'
				}],
				current: 0,
				activeColor: '#007aff'
			};
		},
		onLoad(param) {
			if (!validatenull(this.vuex_accessToken) 
				&& !validatenull(this.vuex_loginSource) 
				&& this.vuex_loginSource==='2') {
				this.$u.api.index({
					loginCheck: true
				}).then(res => {
					if (res.code == '200') {
						uni.reLaunch({
							url: '/pages/extAccess/workbeach/index'
						});
					}
				});
			}else{
				//单点登录测试http://localhost:2888/pages/extAccess/login/socialLogin?code=1111&state=11111
				// alert(JSON.stringify(this.$route.query));
				if(validatenull(this.$route.query.code) || validatenull(this.$route.query.state)){
					uni.showToast({title: 'code或state不允许为空',duration: 2000});
				}else{
					// debugger
					this.$u.api.casLogin({
						tenantId: this.vuex_config.tenantId,
						source: this.vuex_config.socialSource,
						code: this.$route.query.code,
						state: this.$route.query.state,
						grant_type: this.vuex_config.socialSource,
						scope: "all",
					}).then(res => {
						if(res.access_token){
							setTimeout(() => {
								this.setPermission(this);
								uni.reLaunch({
									url: '/pages/extAccess/workbeach/index'
								});
							}, 1000);
						}else if (res.error) {
							uni.showToast({
								title: res.error_description,
								duration: 2000
							});
						}else{
							//404或者未连接服务器返回的html错误
							uni.showToast({
								title: "未连接到服务器！",
								duration: 2000
							});
						}
					});
				}
			}
		},
		methods: {
			
		}
	};
</script>